import request from '@/utils/request' // 引入axios封装
// import store from '@/store/index' // 引入vuex
export const registerApi = ({ username, password, repassword }) => {
  return request({
    url: '/api/reg',
    method: 'post',
    data: {
      username,
      password,
      repassword
    }
  })
}
/**
 *
 * @param {*} param0 {
  username：用户名 password：密码
}
 * @returns promise对象
 */
export const loginApi = ({ username, password }) => {
  return request({
    url: '/api/login',
    method: 'post',
    data: {
      username,
      password
    }
  })
}

/**
 * 发送token支付串
 * @returns 用户的基本信息
 */
export const getUserInfoApi = () => {
  return request({
    url: '/my/userinfo',
    method: 'get'
  })
}

/**
 *
 * @returns 侧边栏的基本数据
 */
export const getAsideApi = () => {
  return request({
    url: '/my/menus',
    method: 'get'
  })
}
/**
 * 更新用户资料
 * @param {*} param0 id 用户名 用户昵称 用户邮箱 用户头像地址
 * @returns 修改用户是否成功的信息
 */
export const getMenusListApi = ({
  id,
  username,
  nickname,
  email,
  user_pic
}) => {
  return request({
    url: '/my/userinfo',
    method: 'put',
    data: {
      id,
      username,
      nickname,
      email,
      user_pic
    }
  })
}
/**
 *上传头像
 * @param {*} avatar base64图片地址
 * @returns 返回用户头像的消息
 */
export const updatedUserAvatarApi = (avatar) => {
  return request({
    url: '/my/update/avatar',
    method: 'PATCH',
    data: {
      avatar
    }
  })
}
// 修改密码
export const resetPasswordApi = ({ old_pwd, new_pwd, re_pwd }) => {
  return request({
    url: '/my/updatepwd',
    method: 'PATCH',
    data: {
      old_pwd,
      new_pwd,
      re_pwd
    }
  })
}
// 文章分类
export const getArtCateApi = () => {
  return request({
    url: '/my/cate/list',
    method: 'get'
  })
}
// 添加分类
export const addArtCateApi = ({ cate_name, cate_alias }) => {
  return request({
    url: '/my/cate/add',
    method: 'post',
    data: {
      cate_name,
      cate_alias
    }
  })
}
// 修改分类
export const amendAtrCateApi = ({ id, cate_name, cate_alias }) => {
  return request({
    url: '/my/cate/info',
    method: 'put',
    data: {
      id,
      cate_name,
      cate_alias
    }
  })
}
// 删除分类
export const removeAtrCateApi = (id) => {
  return request({
    url: '/my/cate/del',
    method: 'delete',
    params: {
      id
    }
  })
}
// 发布文章
// 参数要求是form表单元素
export const PutOutArtCateApi = (fd) => {
  return request({
    url: '/my/article/add',
    method: 'post',
    data: fd
  })
}
// 获取文章列表
export const getArtListApi = ({ pagenum, pagesize, cate_id, state }) => {
  return request({
    url: '/my/article/list',
    method: 'get',
    params: {
      pagenum,
      pagesize,
      cate_id,
      state
    }
  })
}
// 获取文章详情
export const getArtdetailsApi = (id) => {
  return request({
    url: '/my/article/info',
    method: 'get',
    params: {
      id
    }
  })
}
// 删除文章列表
export const removeArtListApi = (id) => {
  return request({
    url: '/my/article/info',
    method: 'delete',
    params: {
      id
    }
  })
}
